﻿/// <reference path="jquery-1.3.2-vsdoc.js" />

function selectAll_changed(ele) {
    if (ele.checked) {
        $('.thm > img').fadeTo(1000, 0.5).addClass("thm_select");
        $('.thumbnail').append("<div class='thm_overlay'></div>");
    }
    else {
        $('.thm > img').fadeTo(1000, 1).removeClass("thm_select");
        $('.thumbnail').contents('.thm_overlay').remove();
    }
}

function btDelete_clicked() {
    var ids = new Array();
    for (i = 0; i < $('.thm_select').length; i++) {
        ids[i] = $('.thm_select:eq(' + i + ')').attr('alt');
    }
    var idstring = ids.join(',');
    jQuery.post('/photos/delete/', { ids: idstring });
    $('.thm_select').parents(".thumbnail").fadeOut(1000, function() {
        $(this).remove();
        if ($('.thumbnail').length == 0) {
            $('#pbuttons').hide();
        }    
    });
    
}

function thm_clicked(ele) {

    if ($(ele).parents(".thumbnail").contents('.thm_overlay').length == 0) {
        $(ele).fadeTo(500, 0.5).addClass("thm_select");
        $(ele).parents(".thumbnail").append("<div class='thm_overlay'></div>");

    }
    else {
        $(ele).fadeTo(500, 1).removeClass("thm_select");
        $(ele).parents(".thumbnail").contents('.thm_overlay').remove();
    }
}

function thm_delete(ele, imageid) {
    jQuery.post('/photos/delete/', { ids: imageid });
    $(ele).parents(".thumbnail").fadeOut(500, function() {
        $(this).remove();
        if ($('.thumbnail').length == 0) {
            $('#pbuttons').hide();
        }   
    });
    
}

function addImage(data) {
    var info = data.split(',');
    //var x = "thm";
    //if ($("#results").contents(".thumbnail").length == 0)
    //    x = "thm thm_select";

    var thumbnail = "<div class='thumbnail'><div class='thm'><img onclick='thm_clicked(this)' src='" + info[1] +
            "' alt='" + info[0] + "' /></div><div><img align='absmiddle' src='/Content/images/cross.gif' /> <a onclick='thm_delete(this," + info[0] + ")'>remove</a></div></div>";
    $(thumbnail).hide().fadeIn().prependTo("#c_photos_results");
    $('#pbuttons').show();
}